package db

import (
	"fmt"
	"github.com/spf13/viper"
	"reflect"
)

const dbproperties_path = "./config/properties/"
const propertiesName = "mongodb.properties"

var config *viper.Viper

type BaseDBAccess interface {
	Save(saveObj BaseSaveObj)
	findById(pojoId int64, objType reflect.Type) any
}

func init() {
	config = viper.New()
	config.AddConfigPath(dbproperties_path)
	config.SetConfigName("mongodb")
	config.SetConfigType("properties")
	err := config.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
	PlayerAccess = &PlayerDBAccess{DBConn: NewMongoDbConn(config.GetString("mongo.player.uri"), config.GetString("mongo.player.dbName"))}
	UserAccess = &UserDBAccess{DBConn: NewMongoDbConn(config.GetString("mongo.user.uri"), config.GetString("mongo.user.dbName"))}
}
